package com.example.springbootmybatisdemo.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Description TODO
 * @Author: cdd
 * @Date: 2020/7/2 17:27
 * @Version: 1.0
 */
@RestController
public class SessionShareController {

    @Value("${server.port}")
    Integer port;

    @GetMapping("/set")
    public String set(HttpSession session) {
        session.setAttribute("content", "一个依赖解决session共享的问题");
        return "当前服务端口为：" + String.valueOf(port);
    }

    @GetMapping("/get")
    public String get(HttpSession session) {
        return session.getAttribute("content") + ":" + port;
    }
}
